#ifndef ____X_TIMER_H____
#define ____X_TIMER_H____

class CTimerBase
{
public:
	CTimerBase(U32 nFrequence);
	virtual ~CTimerBase();

	virtual BOOL onTimer(U32 nCurtime) {return FALSE;}
	void Tick(U32 nCurTime);

	void Start();
	void Stop();
	U32 GetTimerID() {return m_nTimerID;}

	friend class CTimerMgr;

protected:
	S32		m_iEacapeTime;
	U32		m_nLastTickTime;
	BOOL	m_bEnable;
	U32		m_nTimerID;
	U32		m_nFrequence;
};

typedef boost::unordered_map<U32, CTimerBase*>	TimerMap;

class CTimerMgr
{
	SINGLETON_CLASS(CTimerMgr)
	CTimerMgr();
public:
	U32 AddTimer(CTimerBase* pTB);
	void RemoveTimer(CTimerBase* pTB);
	void Tick(U32 nCurtime);
private:
	U32		m_nTimerID;
	TimerMap		m_mapTimers;
};

#endif//____X_TIMER_H____